<?php
$title = array(
	'name'	=> 'post_title',
	'id'	=> 'maxlength_defaultconfig',
	'value' => isset($post[0]['post_title'])?$post[0]['post_title']:set_value('post_title'),
	'class'	=>	'form-control',
	'maxlength'	=>	'25'
);
$upload_image = array(
	'name'	=>	'upload_image'
);

$desc = array(
	'name'	=>	'post_desc'
);

$excerpt = array(
	'name'	=> 'post_excerpt',
	'maxlength'	=> 30,
	'class'	=>	'form-control',
	'placeholder'	=>	'Enter text',
	'value' => isset($post[0]['post_excerpt'])?$post[0]['post_excerpt']:set_value('post_excerpt')
);

$tag = array(
	'name'	=> 'post_tags',
	'id'	=> 'tags_select',
	'type'	=>	'hidden',
	'class'	=>	'form-control select2',
	'value' => isset($post[0]['post_tags'])?$post[0]['post_tags']:set_value('post_tags')
);

$category = array(
	'name'	=> 'post_category',
	'id'	=> 'category_select',
	'type'	=>	'hidden',
	'class'	=>	'form-control select2',
	'value' => isset($post[0]['post_category'])?$post[0]['post_category']:set_value('post_category')
);

?>

<?php
$this->backyard_view->header($post_type);
?>			
			<!-- BEGIN PAGE CONTENT-->
			<div class="row">
				<div class="col-md-12">
					<div class="portlet box blue">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-reorder"></i><?php echo $this->lang->line('post_new'); ?>
							</div>
							<div class="tools"></div>
						</div>
						<div class="portlet-body form">
							<!-- BEGIN FORM-->
							<form action="post/modify" id="post_form" class="form-horizontal form-row-sepe" method="POST">
								<input type="hidden" value="<?php echo isset($post_id)?$post_id:''; ?> " name="post_id"/>
								<div class="form-body">
									<div class="form-group">
										<label class="control-label col-md-3">分類</label>
										<div class="col-md-4">
											<?php echo form_input($category); ?>
												<span for="post_category" class="help-block" style="color:red;"><?php echo form_error($category['name']); ?><?php echo isset($errors[$category['name']])?$errors[$category['name']]:''; ?></span>
										</div>
									</div>
									<div class="form-group">
										<label class="control-label col-md-3">標題<br />*option</label>
										<div class="col-md-4">
												<?php echo form_input($title); ?>
												<span for="post_title" class="help-block" style="color:red;"><?php echo form_error($title['name']); ?><?php echo isset($errors[$title['name']])?$errors[$title['name']]:''; ?></span>
										</div>
									</div>

									<!--file upload-->
									<div class="form-group">
										<label class="control-label col-md-3">圖片</label>
										<div class="col-md-9">
											<?php echo $image_uploader; ?>
											<span for="upload_image" class="help-block" style="color:red;"><?php echo form_error($upload_image['name']); ?><?php echo isset($errors[$upload_image['name']])?$errors[$upload_image['name']]:''; ?></span>
										</div>
									</div>
									<!--END file upload-->
									<!--CK editor-->
									<div class="form-group">
											<div class="form-body">
												<div class="form-group last">
													<label class="control-label col-md-3">描述</label>
													<div class="col-md-9">
														<textarea class="ckeditor form-control" name="post_desc" rows="6">
															<?php
																echo isset($post[0]['post_desc'])?$post[0]['post_desc']:(set_value('post_desc')?set_value('post_desc'):'');
															?>
														</textarea>
														<span for="post_desc" class="help-block" style="color:red;"><?php echo form_error($desc['name']); ?><?php echo isset($errors[$desc['name']])?$errors[$desc['name']]:''; ?></span>
													</div>
												</div>
											</div>
									</div>
									<!--END CK editor-->
									<!--excerpt-->
									<div class="form-group">
										<label class="control-label col-md-3">摘要</label>
										<div class="col-md-4">
											<?php echo form_input($excerpt); ?>
											<span for="post_excerpt" class="help-block" style="color:red;"><?php echo form_error($excerpt['name']); ?><?php echo isset($errors[$excerpt['name']])?$errors[$excerpt['name']]:''; ?></span>
										</div>
									</div>
									<!--END excerpt-->	
									<div class="form-group">
										<label class="control-label col-md-3">Tags</label>
										<div class="col-md-4">
											<?php echo form_input($tag); ?>
											<span for="post_tags" class="help-block" style="color:red;"><?php echo form_error($tag['name']); ?><?php echo isset($errors[$tag['name']])?$errors[$tag['name']]:''; ?></span>
										</div>
									</div>
									
								</div>
								<div class="form-actions fluid">
									<div class="row">
										<div class="col-md-12">
											<div class="col-md-offset-3 col-md-9">
												<button type="submit" class="btn purple" onclick="unbindOnBeforeUnload();"><i class="fa fa-check"></i>修改</button>
												<button type="button" class="btn default" onclick="unbindOnBeforeUnload();saveAsDraft();">存為草稿</button>
											</div>
										</div>
									</div>
								</div>
							</form>
							<!-- END FORM-->
						</div>
					</div>
				</div>
			</div>
<!-- END PAGE CONTENT-->
</div>
</div>
<!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<?php
$this->backyard_view->footer();
?>
<!-- END FOOTER -->
<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
<!-- BEGIN CORE PLUGINS -->
<!--[if lt IE 9]>
    <script src="/assets/plugins/respond.min.js"></script>
    <script src="/assets/plugins/excanvas.min.js"></script> 
    <![endif]-->
<script src="/assets/plugins/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="/assets/plugins/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="/assets/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/assets/plugins/bootstrap/js/bootstrap2-typeahead.min.js" type="text/javascript"></script>
<script src="/assets/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
<script src="/assets/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="/assets/plugins/jquery.blockui.min.js" type="text/javascript"></script>
<script src="/assets/plugins/jquery.cokie.min.js" type="text/javascript"></script>
<script src="/assets/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
<!-- END CORE PLUGINS -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<script type="text/javascript" src="/assets/plugins/bootstrap-select/bootstrap-select.min.js"></script>
<script type="text/javascript" src="/assets/plugins/select2/select2.min.js"></script>
<script type="text/javascript" src="/assets/plugins/jquery-multi-select/js/jquery.multi-select.js"></script>
<script type="text/javascript" src="/assets/plugins/ckeditor/ckeditor.js"></script>
<!-- END PAGE LEVEL PLUGINS -->


<!-- BEGIN CUSTOM SCRIPTS -->
<script src="/assets/scripts/core/app.js"></script>
<script src="/assets/scripts/custom/components-dropdowns.js"></script>
<script src="/assets/scripts/custom/components-editors.js"></script>
<script src="/assets/plugins/fileuploader/fileuploader.js" type="text/javascript"></script>
<script src="/assets/plugins/fileuploader/uploader_function.js" type="text/javascript"></script>
<!-- END CUSTOM SCRIPTS -->
<script>
        jQuery(document).ready(function() {       
           // initiate layout and plugins
           App.init();
           ComponentsDropdowns.init();
           ComponentsEditors.init();

           // image uploader
           if($('#thumbnail-fine-uploader').length > 0){
	    	var thumbnailuploader = new qq.FileUploader({
				element: $('#thumbnail-fine-uploader')[0],
				action: '/image_uploader/uploadToTemp',
				debug: false,
				multiple: false,
				allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
				sizeLimit: 5120000,
				uploadButtonText: '選擇圖片',
				onSubmit: function(id, fileName) {
					var emptyCcount = 0;
					$('#image-thumbnail').find('.empty-image').each(function(i) {
						emptyCcount++;
					});
					
					if(emptyCcount==0){
						alert('reach the upload limit !!');
						return false;
					}
				},
				onComplete: function(id, fileName, responseJSON) {
					if (responseJSON.success) {
						$('#image-thumbnail').find('.empty-image').each(function(i) {
							//if($(this).attr('class') == 'empty-image'){
								$(this).html(responseJSON.thumbs+'<input type="hidden" name="upload_image[]" value="'+responseJSON.filename+'" /><div onclick="cancelUpload(this,\''+responseJSON.filename+'\')" class="cancel_btn">cancel</div>');
								$(this).attr('class','upload-image');
								$('.qq-upload-success').fadeOut(6000);
							//}
							return false;
						});
					}
				}
			});
    	}
    	
    	$(".thumbnails").hover(//for cancel button on imageuploader
			function()
			{	
				$(this).find(".cancel_btn").show();
			},
			function()
			{
				$(this).find(".cancel_btn").hide();
		});
        });   
		
		//page unload
		var loc = window.location.pathname.split('/');
		if(loc[2]=='post_modify'){
			window.onbeforeunload = askConfirm;
			$(window).unload(function() {
 				 //deleteTempFiles();//when form submit error occur,this funcion will delete temp images,so deprecated it 
								});
		}

</script>
<!-- END GOOGLE RECAPTCHA -->
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>